---@diagnostic disable: trailing-space
local extension = Package:new("cangfeng_card", Package.CardPack)
extension.extensionName = "est_test"

Fk:loadTranslationTable{
  ["cangfeng_card"] = "藏锋卡牌",
}
--搬运地址https://gitee.com/buaa18376457
local U = require "packages/utility/utility"

local hidding_sharp_skill = fk.CreateTriggerSkill{
  name = "#hidding_sharp_skill",
  anim_type = "offensive",
  attached_equip = "hidding_sharp",
  events = {fk.EventPhaseStart, fk.PreCardEffect},
  priority = 0.01,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
        return target == player and player:hasSkill(self.name) and player.phase == Player.Finish
        and not player:prohibitUse(Fk:cloneCard("slash"))
    else
        return target == player and table.contains(data.card.skillNames, self.name)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.PreCardEffect then return true end
    local room = player.room
    local targets = table.filter(room.alive_players, function (p) return player:inMyAttackRange(p)
    and not player:isProhibited(p, Fk:cloneCard("slash")) end)
    local tos = room:askForChoosePlayers(player, table.map(targets,Util.IdMapper), 1, 1, "#hidding_sharp-choose", self.name, true)
    if #tos > 0 then
        self.cost_data = tos[1]
        return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      room:notifySkillInvoked(player, self.name, "offensive")
      local to = room:getPlayerById(self.cost_data)
      room:useVirtualCard("slash", nil, player, to, self.name, true)
    else
      local to = room:getPlayerById(data.to)
      local cancel = false
      local players = table.filter(room.alive_players, function (p)
        return not table.contains(data.disresponsiveList or Util.DummyTable, p.id) and not
        table.contains(data.unoffsetableList or Util.DummyTable, p.id)
      end)
      local useEvent = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if data.disresponsive or data.unoffsetable then
        table.removeOne(players, to)
      end
      if #players > 0 then
        local extra_data = Util.DummyTable
        if useEvent then
          extra_data = { useEventId = useEvent.id, effectTo = data.to }
        end
        local prompt = "#hidding_sharp-ask:"..data.to
        local use = room:askForNullification(players, "nullification", "nullification", prompt, true, extra_data)
        if use then
          use.toCard = data.card
          use.responseToEvent = data
          room:useCard(use)
        end
        if data.isCancellOut then
          cancel = true
        end
      end
      if not cancel then
        GameEvent:new(GameEvent.SkillEffect, function ()
          data.card.skill:onEffect(room, data)
        end, room:getPlayerById(data.from), data.card.skill):exec()
      end
      return true
    end
  end,
}
local hidding_sharp_attackrange = fk.CreateAttackRangeSkill{
  name = "#hidding_sharp_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill(hidding_sharp_skill) then
        return 1
    end
    return 0
  end,
}
hidding_sharp_skill:addRelatedSkill(hidding_sharp_attackrange)
Fk:addSkill(hidding_sharp_skill)

local hidding_sharp = fk.CreateTreasure{
  name = "hidding_sharp",
  suit = Card.Spade,
  number = 5,
  equip_skill = hidding_sharp_skill,
}
extension:addCard(hidding_sharp)

Fk:loadTranslationTable{
    ["hidding_sharp"] = "藏锋",
    ["#hidding_sharp_skill"] = "藏锋",
    [":hidding_sharp"] = "装备牌·宝物<br/><b>宝物技能</b>：你的攻击范围+1；结束阶段，你可以视为对攻击范围内的一名角色使用一张【杀】，此【杀】仅能被【无懈可击】抵消。",
    ["#hidding_sharp-choose"] = "藏锋：视为使用一张【杀】，此【杀】仅能被【无懈可击】抵消",
    ["#hidding_sharp-ask"] = "藏锋：你可以使用【无懈可击】抵消对 %src 使用的【杀】",
}


return extension
